package org.hzandyy.framework.liteflow.context;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.hzandyy.framework.liteflow.support.Obj;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hz
 * @since 2023/12/8 10:51
 */
@Getter
@Setter
public class CustomContext {

    private Map<String, Obj> map = new HashMap<>();

    public void setData(String key, Obj o) {
        map.put(key, o);
    }

    public Obj getDate(String key) {
        return map.get(key);
    }

    @Override
    public String toString() {
        try {
            return new ObjectMapper().writeValueAsString(map);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
